class Solution3 {
    public int rangeBitwiseAnd(int left, int right) {
        if (left == right)
            return left;
        int index = -1, ans = 0;
        for (int i = 0; i < 32; i++) {
            if (left == right) {
                index = i;
                ans = left;
                break;
            }
            left >>= 1;
            right >>= 1;
        }
        if (index >= 0)
            return ans << index;
        else
            return 0;
    }
}